Skip to content

harden ember-server — auth rate limiting, pubsub limits, integer safety - #102

Merged
kacy merged 4 commits into
mainfrom
harden/ember-server
Feb 12, 2026
Merged

harden ember-server — auth rate limiting, pubsub limits, integer safety#102
kacy merged 4 commits into
mainfrom
harden/ember-server

Conversation

@kacy

@kacy kacy commented Feb 12, 2026

Copy link
Copy Markdown
Owner

summary

hardens the server crate against several attack vectors and integer safety issues identified during security audit:

  • auth brute-force protection: track failed AUTH attempts per connection, disconnect after 10 failures (matches Redis 6.2+ behavior). applied to both sharded and concurrent connection handlers.
  • pub/sub subscription limits: cap subscriptions per connection at 10,000 to prevent memory exhaustion from broadcast channel creation. cap PSUBSCRIBE pattern length at 256 bytes to prevent pathological glob backtracking.
  • slowlog integer safety: cap as_micros(), entry IDs, and timestamps with .min(i64::MAX) before casting to prevent silent truncation on very large values.
  • drain_connections safety: use try_from with saturating fallback instead of bare as u32 cast on max_conn.

what was tested

  • all 43 ember-server unit tests pass
  • cargo clippy -p ember-server clean
  • cargo check -p ember-server clean
  • manual review of all as i64/as u32/as usize casts in the crate

design considerations

  • auth failure counter is per-connection (not global) to avoid legitimate clients being locked out by another client's failures
  • subscription limit of 10,000 is generous enough for any legitimate use case while preventing abuse
  • pattern length of 256 bytes matches practical channel naming conventions; longer patterns almost certainly indicate abuse or a bug

kacy added 4 commits February 12, 2026 11:13
- add MAX_AUTH_FAILURES (10) constant in connection_common.rs
- track failed AUTH attempts per connection, disconnect after 10 failures
- apply to both sharded (connection.rs) and concurrent handler
- cap slowlog integer fields with .min(i64::MAX) before as-cast to
  prevent truncation on very large IDs or timestamps
- add MAX_SUBSCRIPTIONS_PER_CONN (10,000) to prevent memory exhaustion
  from a single client creating unbounded broadcast channels
- add MAX_PATTERN_LEN (256) to prevent pathological glob backtracking
  from very long PSUBSCRIBE patterns
- enforce both limits in handle_sub_command with clear error messages
use try_from with saturating fallback instead of bare `as u32` cast
on max_conn, preventing truncation if a very large value is configured.
@kacy
kacy merged commit 43e2844 into main Feb 12, 2026
7 checks passed
@kacy
kacy deleted the harden/ember-server branch February 12, 2026 16:32
kacy added a commit that referenced this pull request Feb 19, 2026
…ty (#102)

* harden: auth brute-force protection and slowlog integer safety

- add MAX_AUTH_FAILURES (10) constant in connection_common.rs
- track failed AUTH attempts per connection, disconnect after 10 failures
- apply to both sharded (connection.rs) and concurrent handler
- cap slowlog integer fields with .min(i64::MAX) before as-cast to
  prevent truncation on very large IDs or timestamps

* harden: pub/sub subscription limits and pattern length cap

- add MAX_SUBSCRIPTIONS_PER_CONN (10,000) to prevent memory exhaustion
  from a single client creating unbounded broadcast channels
- add MAX_PATTERN_LEN (256) to prevent pathological glob backtracking
  from very long PSUBSCRIBE patterns
- enforce both limits in handle_sub_command with clear error messages

* harden: safe u32 conversion in drain_connections

use try_from with saturating fallback instead of bare `as u32` cast
on max_conn, preventing truncation if a very large value is configured.

* fmt: rustfmt import ordering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant